<?php
/*
    Authors and license
*/

include_once(dirname(__FILE__).'/../../libraries/security.php');
include_once(dirname(__FILE__).'/user_sql.php');
include_once(dirname(__FILE__).'/user_sql_table.php');

if(isset($_SESSION['logged'])) // user logged in?
{
	$id = $_SESSION['id']; // grab user id to sql querry
	$user_data = grabUserData($id,$user_caption_amount); // grabbing all data about logged in user
	
	if(isset($_POST['edit_sent'])){
		if($_POST['password']!=""){ // user want to change password
			if(codepass($_POST['password'])==codepass($_POST['password2'])){ // both password are same, we can change it
				$user_data[($user_caption['Password'])]=codepass($_POST['password']);
			}
			else {
				echo 'pw are not same';
			}
		}
		
		$user_data[($user_caption['Name'])]=clear($_POST['name']);
		$user_data[($user_caption['Surname'])]=clear($_POST['surname']);
		
		exportUserData($user_caption_name,$user_data,$user_caption_amount);
		
		
	}	
	else {
		
		printUserProfileForm($user_data,$user_caption); // printing form with some standard options to edit
	}	
}
//  if user is not logged in nothing realy should be done. Just no efect.
?>